package com.afkt.project.ui.slice;


import com.afkt.project.base.app.BaseActivity;
import com.ohos.afkt.ResourceTable;
import com.dev.widget.ui.FlowLikeView;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

import java.util.Calendar;

public class FlowLikeSlice extends BaseActivity {

    private DirectionalLayout bar_Layout;
    private DirectionalLayout bar;
    private Image select_retuen;


    @Override
    protected int baseLayoutId() {
        return ResourceTable.Layout_activity_flow_like;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {
        select_retuen.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                // LogUtils.error(TAG, "return 点击");
                onBackPressed();
            }
        });
    }

    @Override
    protected void onActive() {
        super.onActive();
        vidAflFlowlike.release();

    }

    @Override
    protected void onStop() {
        super.onStop();
        vidAflFlowlike.cleanAnimator();
    }

    @Override
    protected void onBackground() {
        super.onBackground();

        bar_Layout.removeAllComponents();
    }

    private FlowLikeView vidAflFlowlike;
    private long lastClickTime;
    private boolean isFirst = true;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        bar_Layout = (DirectionalLayout) findComponentById(ResourceTable.Id_base_view_barLayout);
        bar = (DirectionalLayout) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_sheet_dialog_bar, null, false);
        Text text = (Text) bar.findComponentById(ResourceTable.Id_titleText);
        select_retuen = (Image) bar.findComponentById(ResourceTable.Id_sheet_dialog_return);
        text.setText("自定义点赞效果 View");
        bar_Layout.addComponent(bar);
        vidAflFlowlike = (FlowLikeView) findComponentById(ResourceTable.Id_vid_afl_flowlike);
        lastClickTime = System.currentTimeMillis();
        initValue();
    }

    private void initValue() {
        vidAflFlowlike.setDrawablesById(ResourceTable.Media_icon_live_brow_1, ResourceTable.Media_icon_live_brow_2, ResourceTable.Media_icon_live_brow_3,
                ResourceTable.Media_icon_live_brow_4, ResourceTable.Media_icon_live_brow_5);
        vidAflFlowlike.setClickable(true);
        vidAflFlowlike.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                long now = System.currentTimeMillis();
                if (now - lastClickTime > 200 || isFirst) {
                    lastClickTime = now;
                    vidAflFlowlike.like();
                    vidAflFlowlike.like();
                    isFirst = false;
                }
            }
        });
    }

}
